var setting = {
	check: {
		enable: true,
		chkStyle: "radio",
		radioType: "all"
	},
	async: {
		enable: true,
		url: getUrl
	},
	data: {
		simpleData: {
		  enable: true
	    }
	},
	view: {
		expandSpeed: ""
	},
	callback: {
		beforeExpand: beforeExpand,
		onAsyncSuccess: onAsyncSuccess,
		onAsyncError: onAsyncError
	}
};
function getUrl(treeId, treeNode) {
	var sign=treeNode.id.substr(0,1);
	var cid=treeNode.id.substr(1);
	if(sign=='C'){
		return "../base/queryTree_Ban.action?cid="+cid+"&urlSign=fees&ymonth="+$("#ymonth").val();
	}else if(sign=="B"){
		return "../base/queryTree_Unit.action?bid="+cid+"&urlSign=fees&ymonth="+$("#ymonth").val();
	}else if(sign=="U"){
		return "../base/queryTree_Room.action?uid="+cid+"&urlSign=fees&ymonth="+$("#ymonth").val();
	}
};
function beforeExpand(treeId, treeNode) {
	if (!treeNode.isAjaxing) {
		ajaxGetNodes(treeNode, "refresh");
		return true;
	} else {
		alert("正在下载数据中，请稍后展开节点。。。");
		return false;
	}
};
function ajaxGetNodes(treeNode, reloadType) {
	var zTree = $.fn.zTree.getZTreeObj("menup");
	if (reloadType == "refresh") {
		treeNode.icon = "../script/ztree/css/zTreeStyle/img/loading.gif";
		zTree.updateNode(treeNode);
	}
	zTree.reAsyncChildNodes(treeNode, reloadType, true);
};
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
	var zTree = $.fn.zTree.getZTreeObj("menup");
	alert("异步获取数据出现异常。");
	treeNode.icon = "";
	zTree.updateNode(treeNode);
};
function onAsyncSuccess(event, treeId, treeNode, msg) {
	var zTree = $.fn.zTree.getZTreeObj("menup"),
	totalCount = treeNode.count;
	treeNode.icon = "";
	zTree.updateNode(treeNode);
	zTree.selectNode(treeNode.children[0]);
};

$(document).ready(function(){
	$.post("../base/query_RoomInfo.action",{"urlSign":"fees","ymonth":$("#ymonth").val()},function(result){
		$.fn.zTree.init($("#menup"), setting, result.communitys);
	});
	
});

function showFees(unitid,urlSign){
	var ymonth=$("#ymonth").val();
	if(ymonth==null || ymonth=='' || ymonth==undefined){
		alert('请选择记账月份');
		return;
	}
	if(unitid.indexOf("R")=='1'){
		$('#bodycontent').html('正在生成收费数据，请稍等...');
		$('#myModal').modal('show');
		$.post("../fees/checkFees_Records.action",{"unitid":unitid.substr(2),"urlSign":urlSign,"ymonth":ymonth},function(result){
			$('#myModal').modal('hide');
			if(result.msg=="succ"){
			    window.location.assign("../fees/queryFees_Records.action?unitid="+unitid.substr(2)+"&urlSign="+urlSign+"&ymonth="+ymonth);
			}else{
				alert(result.msg);
			}
		});
		
	}else{
		window.location.assign("../fees/queryPage_Records.action?unitid="+unitid+"&urlSign="+urlSign+"&ymonth="+ymonth);
	}
	
}
function showDateRead(){
	var unitid=$("#unitid").val();
	if(unitid!=null && unitid!="" && unitid!=undefined){
		var ymonth=$("#ymonth").val();
		window.location.assign(basePath+"/fees/queryPage_Records.action?unitid="+unitid.substr(1)+"&urlSign=fees&ymonth="+ymonth);
	}
}
function printnotice(){
	var zTree = $.fn.zTree.getZTreeObj("menup");
	var ids=zTree.getCheckedNodes(true);
	if(ids.length<=0){
		alert('请在左侧套户资料中选择要打印的单元.');
		return;
	}
	var ymonth=$("#ymonth").val();
	if(ymonth==null || ymonth=='' || ymonth==undefined){
		alert('请选择记账月份');
		return;
	}
	$('#bodycontent').html('正在生成打印数据，请稍等...');
	$('#myModal').modal('show');
	var rid=ids[0].id;
	
	$.post("../fees/checkConfig_Records.action",{"unitid":rid,"urlSign":"fees","ymonth":ymonth},function(result){

		if(result.msg=="succ"){
			$("#print_notice").attr("src","../fees/printNotice_Records.action?unitid="+rid+"&ymonth="+ymonth);
		}else{
			$('#myModal').modal('hide');
			if(result.msg.indexOf("0")>=0){
				$("#confirm_info").html(result.msg.substr(2));
				$('#confirm_win').modal('show');
				$("#confirm_next").bind("click",function(){
					$('#confirm_win').modal('hide');
					$('#myModal').modal('show');
					$.post("../fees/checkConfig_Records.action",{"unitid":rid,"urlSign":"fees","ymonth":ymonth,"sign":1},function(result){
						if(result.msg.indexOf("1")>=0){
							$("#confirm_info").html(result.msg.substr(2));
							$('#confirm_win').modal('show');
							$("#confirm_next").bind("click",function(){
								$('#confirm_win').modal('hide');
								$('#myModal').modal('show');
								$("#print_notice").attr("src","../fees/printNotice_Records.action?unitid="+rid+"&ymonth="+ymonth);
								$("#confirm_next").unbind("click");
							});
						}else if(result.msg=="succ"){
							$("#print_notice").attr("src","../fees/printNotice_Records.action?unitid="+rid+"&ymonth="+ymonth);
						}else{
							alert(result.msg);
						}
					});
					$("#confirm_next").unbind("click");
				});
				
			}else{
				alert(result.msg);
			}
		}
	});
	
}